package com.dries.portal.module.coupon.controller;

import com.dries.common.api.CommonResult;
import com.dries.portal.module.coupon.entity.Voucher;
import com.dries.portal.module.coupon.service.IVoucherService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 代金券
 *
 * @author dries
 * @email samphsanie@gmail.com
 * @date 2020-09-30 15:32:29
 */
@RestController
@RequestMapping("coupon/voucher")
public class VoucherController {

    @Resource
    private IVoucherService voucherService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public CommonResult list(){
        List<Voucher> list = voucherService.list();
        return CommonResult.success(list);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public CommonResult save(@RequestBody Voucher voucher){
		voucherService.save(voucher);

        return CommonResult.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public CommonResult update(@RequestBody Voucher voucher){
		voucherService.updateById(voucher);

        return CommonResult.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public CommonResult delete(@RequestBody Integer[] ids){
		voucherService.removeByIds(Arrays.asList(ids));

        return CommonResult.success();
    }

}
